<?php
/*
 * File: login.php
 * Created: 18 июня 2007
 * Author: Andrew Dashin <dash@andrewdashin.com>
 * 
 * Description:
 * 
 * This is login service.
 * 
 * Return values:
 * 
 * 0 Successfully logged in!
 * 1 Login is not defined!
 * 2 Password is not defined!
 * 3 Login or password is not correct!
 * 4 User is banned!
 * 
 */

if (!isset($_POST['login']) or empty($_POST['login'])) {
	echo '1'; // Login is not defined!
} else {
	if (!isset($_POST['password']) or empty($_POST['password'])) {
		echo '2'; // Password is not defined!
	} else {
		
        $db = MySQL::getInstance();

		if (!$row = $db->fetchAssoc(
            $db->sql("SELECT * FROM `users` WHERE `login` = ':0' AND `password` = PASSWORD(':1') AND `active` = 1 AND `email_confirmed` = 1")->bind($_POST['login'], $_POST['password'])
            )) {
			echo '3'; // Login or password is not correct!
		} else {
			$_SESSION['userid'] = $row['login'];
            echo '0'; // Successfully logged in!
		}
		
	}
}
?>
